//
//  VPJumpSettingViewController.m
//  VPPublicUntilitisForPod
//
//  Created by caixiang on 2017/6/21.
//  Copyright © 2017年 vernepung. All rights reserved.
//

#import "VPJumpSettingViewController.h"
#import "UtilsMacro.h"
#import "ConstMacro.h"
#import "NSArray+Additional.h"
#import "Helper+Permission.h"

@interface VPJumpSettingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) UITableView *settingTableView;
@property (strong, nonatomic) NSArray *datasource;

@end

@implementation VPJumpSettingViewController
- (void)setStaticDatas {
    self.datasource = @[@"相机",@"相册",@"推送"];
}

- (void)setupViews {
    [self.view addSubview:self.settingTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datasource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *settingCellIdentifier = @"settingCellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingCellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:settingCellIdentifier];
    }
    cell.textLabel.text = [self.datasource objectAtIndexChecked:indexPath.row];
    
    if (indexPath.row == 0) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
//            BOOL allow = [Helper checkingVideoPermission];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                NSString *str = allow ? @"允许" : @"拒绝";
//                cell.detailTextLabel.text = [NSString stringWithFormat:@"当前可使用状态:%@",str];
//            });
        });
    }else if (indexPath.row == 1) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
//            BOOL allow = [Helper checkingPhotoPermission];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                NSString *str = allow ? @"允许" : @"拒绝";
//                cell.detailTextLabel.text = [NSString stringWithFormat:@"当前可使用状态:%@",str];
//            });
        });
    }else if (indexPath.row == 2) {
        [Helper checkingNotificationPermisssionWithCompleteBlock:^(BOOL result) {
            BOOL allow = result;
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *str = allow ? @"允许" : @"拒绝";
                cell.detailTextLabel.text = [NSString stringWithFormat:@"当前可使用状态:%@",str];
            });
        }];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger row = indexPath.row;
    openUrlInSafari(UIApplicationOpenSettingsURLString);
}

#pragma mark - getter & setter
- (UITableView *)settingTableView {
    if (!_settingTableView) {
        _settingTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kMainBoundsWidth, kMainBoundsHeight - kNavBarHeightWithStatusBarHeight) style:UITableViewStylePlain];
        _settingTableView.delegate = self;
        _settingTableView.dataSource = self;
        _settingTableView.rowHeight = 49.f;
        _settingTableView.tableFooterView = [UIView new];
    }
    return _settingTableView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
